package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Score;
import com.ruoyi.system.service.IScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生成绩Controller
 *
 * @author ruoyi
 * @date 2022-04-27
 */
@RestController
@RequestMapping("/system/Score")
public class ScoreController extends BaseController {
    @Autowired
    private IScoreService scoreService;

    /**
     * 查询学生成绩列表
     */
    @PreAuthorize("@ss.hasPermi('system:Score:list')")
    @GetMapping("/list")
    public TableDataInfo list(Score score) {
        startPage();
        List<Score> list = scoreService.selectScoreList(score);
        return getDataTable(list);
    }

    /**
     * 导出学生成绩列表
     */
    @PreAuthorize("@ss.hasPermi('system:Score:export')")
    @Log(title = "学生成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Score score) {
        List<Score> list = scoreService.selectScoreList(score);
        ExcelUtil<Score> util = new ExcelUtil<Score>(Score.class);
        util.exportExcel(response, list, "学生成绩数据");
    }

    /**
     * 获取学生成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Score:query')")
    @GetMapping(value = "/{sid}")
    public AjaxResult getInfo(@PathVariable("sid") Integer sid) {
        return AjaxResult.success(scoreService.selectScoreBySid(sid));
    }

    /**
     * 新增学生成绩
     */
    @PreAuthorize("@ss.hasPermi('system:Score:add')")
    @Log(title = "学生成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Score score) {
        return toAjax(scoreService.insertScore(score));
    }

    /**
     * 修改学生成绩
     */
    @PreAuthorize("@ss.hasPermi('system:Score:edit')")
    @Log(title = "学生成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Score score) {
        return toAjax(scoreService.updateScore(score));
    }

    /**
     * 删除学生成绩
     */
    @PreAuthorize("@ss.hasPermi('system:Score:remove')")
    @Log(title = "学生成绩", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sids}")
    public AjaxResult remove(@PathVariable Integer[] sids) {
        return toAjax(scoreService.deleteScoreBySids(sids));
    }
}
